using UnityEngine;
using System.Collections;

public class Moon : MonoBehaviour
{
	public Transform		_rotationObject;
	public float			_speed;
	public Vector3			_rotationAxis;
	private	float			_angle;
	public float			_distance;
	public string			_name;

	// Use this for initialization
	void Start ()
	{
		_rotationAxis.Normalize();
		Vector3 _pos = (gameObject.transform.position);
		_angle = Mathf.Atan2( _pos.y, _pos.x );
		if( _distance <= 0 )
			_distance = (_rotationObject.position - gameObject.transform.position).magnitude;
		Debug.Log( _name + "angle:" + _angle );
	}
	
	// Update is called once per frame
	void Update ()
	{
		_angle += _speed * Time.deltaTime;

		gameObject.transform.position = 
				( new Vector3(	_rotationAxis.x * Mathf.Cos( _angle ),
								_rotationAxis.y * Mathf.Sin( _angle ),
								_rotationAxis.z * Mathf.Cos( _angle ))
				+ _rotationObject.position ) * _distance;
	}

}